// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require jquery.Jcrop.min
//= require jquery.tagsinput.min
//= require ckeditor/init
//= require bootstrap
//= require_tree .


;(function($) {
  $.fn.applySlideAnimation = function(direction){
    this.hide().show("slide", { direction: direction, distance: "15px", easing: 'easeOutExpo' }, 500)
  }
})(jQuery);

function animateFlashMessages(){
  // animate the flash messages
  $("#flash_success").hide()
                     .show("slide", { direction: "up", easing: "easeOutCirc" }, 100)
                     .delay(1000)
                     .hide("fade", "fast")
  $("#flash_error").hide()
                   .show("slide", { direction: "up", easing: "easeOutCirc" }, 100)
                   .delay(1000)
                   .hide("fade", "fast")
}

// function applySlideAnimation(obj, direction){
//   obj.hide().show("slide", { direction: direction, distance: "15px", easing: 'easeOutExpo' }, 500)
// }

// extend Array with a function called 'remove' which remove specific element in an array
Array.prototype.remove = function(e) {
  var t, _ref;
  if ((t = this.indexOf(e)) > -1) {
    return ([].splice.apply(this, [t, t - t + 1].concat(_ref = [])), _ref);
  }
};

$(document).ready(function(){
  // Animate the flash messages
  animateFlashMessages();

  // Global function for datepicker
  $('body').on('mouseenter', '.dpicker', function(){
    $this = $(this)
    $this.datepicker({
      format: 'dd/mm/yyyy'
    }).on("changeDate", function(){
      $this.datepicker('hide')
    })
  })

  // Global function for adding data-remote=true to will_paginate links
  $('body').on('click', '.pagination a', function(){
    $(this).attr('data-remote', 'true');
  })

  // Blur effects
  // $('.blur').blurjs({
  //   source: 'body',
  //   overlay: 'rgba(255,255,255,0.8)'
  // });
});

//this code for checkbox selected on lookup table (by:nano)
  $(function(){
    $('body').on("click", "#checkall", function(event) {
      if(this.checked) {
        // Iterate each checkbox
        $(':checkbox').each(function() {
          this.checked = true;
        });
      }
      if(!this.checked) {
        // Iterate each checkbox
        $(':checkbox').each(function() {
          this.checked = false;
        });
      }
    });
  });

  $(function() {
    $('body').on("click", ".checkbox-selected", function(){
      $('#btn_selected').prop('disabled',$('.checkbox-selected > :checkbox:checked').length == 0);
    });
  });
//end
